<?php
namespace app\api\controller;
use app\api\validate\MemberValidate;
use app\common\service\EmailTemplateService;
use app\index\Validate\LoginValidate;
use think\Cache;
use think\exception\ValidateException;
use zyw\captcha\facade\Captcha;
use think\helper\Str;
class Login extends RestBaseController
{
    public function register()
    {
        $post = $this->request->post();
        try {
            validate(MemberValidate::class)->scene("register")->check($post);
        } catch (ValidateException $e) {
            throw new ValidateException($e->getError());
        }

    }

    public function login()
    {

    }

    public function verify()
    {

        $this->success("ok", Captcha::create());
    }

    public function sendEmail()
    {
        $post = $this->request->post();
        try {
            validate(LoginValidate::class)->scene("send_email")->check($post);
        } catch (ValidateException $e) {
            throw new ValidateException($e->getError());
        }
        $code = Str::random(4, 1);
        $sendKey = sprintf("%s%s", config("email_register_key"), $post["email"]);
        Cache::store("redis")->set(config("email_register_key"), $code, 600);

    }
}